package org.rcloud.io.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.PictureMapper;
import org.rcloud.io.model.Picture;
import org.rcloud.io.service.PictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/3/3.
 */
@Service(value = "PictureService")
public class PictureServiceImpl implements PictureService {
    @Autowired
    private PictureMapper pictureMapper;


    @Override
    public ResultVo deleteByPrimaryKey(Picture id) {
        try {
            int i = pictureMapper.deleteByPrimaryKey(id);
            return ResultVo.setOK(i);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo insert(Picture record) {

        if (record.equals("") || record == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                pictureMapper.insert(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public ResultVo insertSelective(Picture record) {

        if (record.equals("") || record == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                pictureMapper.insertSelective(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public ResultVo selectByPrimaryKey(Picture id) {

        try {
            Picture picture = pictureMapper.selectByPrimaryKey(id);
            return ResultVo.setOK(picture);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public PageVo<Picture> getByActivid(Picture record) {

        try {
            List<Picture> list = pictureMapper.selectByActivid(record);
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public PageVo<Picture> selectByActivcopyid(Picture id) {

        try {
            List<Picture> list = pictureMapper.selectByActivcopyid(id);
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo updateByPrimaryKeySelective(Picture record) {


        try {
            pictureMapper.updateByPrimaryKeySelective(record);
            return ResultVo.setOK(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo updateByPrimaryKey(Picture record) {

        try {
            pictureMapper.updateByPrimaryKey(record);
            return ResultVo.setOK(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public PageInfo<Picture> selectByOther(JSONObject params){
        List<Picture> pictureList = pictureMapper.selectByOther(params);
        PageInfo<Picture> pageInfo = new PageInfo<>(pictureList);
        return pageInfo;

    }
}
